package com.cheyun.netsalev3.tencenttim.thirdpush;

import android.app.Activity;

import com.cheyun.netsalev3.tencenttim.utils.DemoLog;
import com.cheyun.netsalev3.tencenttim.utils.PrivateConstants;
import com.heytap.msp.push.HeytapPushManager;
import com.huawei.android.hms.agent.HMSAgent;
import com.huawei.android.hms.agent.HMSAgent$Push;
import com.huawei.android.hms.agent.common.handler.ConnectHandler;
import com.huawei.android.hms.agent.push.handler.GetTokenHandler;
import com.tencent.imsdk.utils.IMFunc;

public class ThirdRegIdMgr {
    private static String TAG = ThirdRegIdMgr.class.getSimpleName();
    public static void prepareThirdPushToken(final Activity context) {
//        ThirdPushTokenMgr.getInstance().setPushTokenToTIM();

        if (ThirdPushTokenMgr.USER_GOOGLE_FCM) {
            return;
        }
        if (IMFunc.isBrandHuawei()) {
            // 华为离线推送
            HMSAgent.connect(context, new ConnectHandler() {
                @Override
                public void onConnect(int rst) {
                    DemoLog.i(TAG, "huawei push HMS connect end:" + rst);
                }
            });
            getHuaWeiPushToken();
        }
        if (IMFunc.isBrandVivo()) {
            // vivo离线推送
//            PushClient.getInstance(context.getApplicationContext()).turnOnPush(new IPushActionListener() {
//                @Override
//                public void onStateChanged(int state) {
//                    if (state == 0) {
//                        String regId = PushClient.getInstance(context.getApplicationContext()).getRegId();
//                        DemoLog.i(TAG, "vivopush open vivo push success regId = " + regId);
//                        ThirdPushTokenMgr.getInstance().setThirdPushToken(regId);
////                        ThirdPushTokenMgr.getInstance().setPushTokenToTIM();
//                    } else {
//                        // 根据 vivo 推送文档说明，state = 101表示该 vivo 机型或者版本不支持 vivo 推送，详情请参考 vivo 推送常见问题汇总
//                        DemoLog.i(TAG, "vivopush open vivo push fail state = " + state);
//                    }
//                }
//            });
        }
        if(IMFunc.isBrandOppo()){
            HeytapPushManager.init(context, true);
            if (com.heytap.msp.push.HeytapPushManager.isSupportPush()) {
                // oppo离线推送
                OPPOPushImpl oppo = new OPPOPushImpl();
                oppo.createNotificationChannel(context);
                com.heytap.msp.push.HeytapPushManager.register(context,PrivateConstants.OPPO_PUSH_APPKEY, PrivateConstants.OPPO_PUSH_APPSECRET,oppo);
            }
        }
    }

    private static void getHuaWeiPushToken() {
        HMSAgent$Push.getToken(new GetTokenHandler() {
            @Override
            public void onResult(int rst) {
                DemoLog.i(TAG, "huawei push get token result code: $rtnCode:"+rst);
            }
        });
    }


}
